package cn.dodgeball.java;

import cn.dodgeball.util.Const;
import cn.dodgeball.util.PClass;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GameOver extends JPanel implements ActionListener {
    JLabel score = new JLabel(String.valueOf((Const.currentTime-Const.startTime)));
    public GameOver() {
        init();
    }

    public void init() {
        setBounds((Const.WIDTH-400)/2, (Const.HEIGHT-400)/2, 400, 400);
        setBackground(new Color(255, 255, 255, 100));
        setLayout(null);

        // 大标题
        JLabel title = new JLabel("挑战结束");
        title.setHorizontalAlignment(SwingConstants.CENTER);
        title.setBounds(0, 0, 400, 100);
        title.setFont(new Font("宋体 ", Font.BOLD, 60));
        title.setForeground(Color.orange);
        add(title);

        // 成绩标题
        JLabel scoreTitle = new JLabel("最终成绩");
        scoreTitle.setHorizontalAlignment(SwingConstants.CENTER);
        scoreTitle.setBounds(0, 100, 400, 50);
        scoreTitle.setFont(new Font("宋体 ", Font.BOLD, 36));
        scoreTitle.setForeground(Color.orange);
        add(scoreTitle);

        // 分数
        score.setHorizontalAlignment(SwingConstants.CENTER);
        score.setBounds(0, 150, 400, 50);
        score.setFont(new Font("宋体 ", Font.BOLD, 36));
        score.setForeground(Color.orange);
        add(score);

        // 按钮
        GameButton reStart =new GameButton("再来一局",100,234,false);
        reStart.addActionListener(this);
        add(reStart);
        GameButton home =new GameButton("主页",reStart.getX(),reStart.getY()+80,true);
        home.addActionListener(this);
        add(home);
        GameButton set =new GameButton("设置",reStart.getX()+ Const.LARGEBUTTON_WIDTH - Const.SMALLBUTTON_WIDTH,reStart.getY()+80,true);
        set.addActionListener(this);
        add(set);
    }

    public void start(){
        score.setText(String.valueOf((Const.currentTime-Const.startTime)));
        setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        switch (e.getActionCommand()){
            case "再来一局":
                PClass.gamePanel.start();
                break;
            case "主页":
                PClass.gamePanel.close();
                break;
            case "设置":
                PClass.set.setting("gamePanel");
                break;
        }
    }
}
